package cond

import cond "clientDemo/service/cond"

func (m *CondModule) RegeditDataSource(categoryId uint32, fn cond.DataSourceFunction) {
	m.datasourceMap[categoryId] = fn
}
func (m *CondModule) RegeditComparer(type1 cond.Comparer_Type, fn cond.DataComparerFunction) {
	m.comparerMap[type1] = fn
}
func (m *CondModule) RegeditOperate(type1 cond.Operate_Type, fn cond.DataOperateFunction) {
	m.operateMap[type1] = fn
}

func (m *CondModule) RegeditUpdateDataSource(categoryId uint32, fn cond.DataSourceUpdateFunction) {
	m.datasourceUpdateMap[categoryId] = fn
}
func (m *CondModule) GetRoleGlobalData(roleId uint32, param []interface{}) int64 {
	if len(param) < 2 {
		return 0
	}
	dataType, ok := param[0].(uint32)
	if !ok {
		return 0
	}
	if dataType == uint32(cond.Cond_ValueParamType_OpenDay) {
		return int64(m.openDayData)
	}
	return 0
}
func (m *CondModule) GetRoleVariableData(roleId uint32, param []interface{}) int64 {
	variableData, ok := m.variableData[roleId]
	if !ok {
		return 0
	}
	if len(param) < 2 {
		return 0
	}
	dataType, ok := param[0].(uint32)
	if !ok {
		return 0
	}
	if dataType == uint32(cond.Cond_ValueParamType_Variable) {
		variableId, ok := param[1].(uint32)
		if !ok {
			return 0
		}

		data, ok := variableData.Data[variableId]
		if ok {
			return data.DataInt32
		}
	}
	return 0
}
func (m *CondModule) GetRoleGrowthData(roleId uint32, param []interface{}) int64 {
	growthData, ok := m.growthData[roleId]
	if !ok {
		return 0
	}
	if len(param) < 2 {
		return 0
	}
	dataType, ok := param[0].(uint32)
	if !ok {
		return 0
	}
	if dataType == uint32(cond.Cond_ValueParamType_Growth_Level) {
		growthId, ok := param[1].(uint32)
		if !ok {
			return 0
		}

		data, ok := growthData.Data[growthId]
		if ok {
			return data.Level
		}
	}
	return 0
}
func (m *CondModule) GetRoleChatData(roleId uint32, param []interface{}) int64 {
	chatData, ok := m.chatData[roleId]
	if !ok {
		return 0
	}
	if len(param) < 2 {
		return 0
	}
	dataType, ok := param[0].(uint32)
	if !ok {
		return 0
	}
	if cond.Cond_ValueParamType_Chat_Num == cond.ValueParam_Type(dataType) {
		channelId, ok := param[1].(uint32)
		if !ok {
			return 0
		}
		data, ok := chatData.Data[channelId]
		if ok {
			return data.TalkCount
		}
	}
	return 0
}
